<template>
<div class='ygbh-footer'>
	<div class="footer-l" v-if='pervHashObj.menuUrl'>
		<router-link class='footer-link' :to='pervHashObj.menuUrl'>&lt;&nbsp;{{pervHashObj.title}}</router-link>
	</div>
	<div class="footer-r" v-if='nextHashObj.menuUrl'>
		<router-link class='footer-link' :to='nextHashObj.menuUrl'>{{nextHashObj.title}}&nbsp;&gt;</router-link>
	</div>
</div>
</template>

<script>
import menuList from '../common/menuList'

export default {
	name: 'Ygbhfooter',
	props: {
		msg: String
	},
	data () {
		return {
			listData: JSON.parse(JSON.stringify(menuList)),
			nowHashStr: '',
			pervHashObj: {},//上一个
			nextHashObj: {},//下一个
		};
	},
	methods: {
		// 获取上下一个 hash
		getPrevNextHashObj () {
			let waitHashObj;
			let waitHashObjFlag = false;
			this.pervHashObj = {};
			this.nextHashObj = {};
			
			this.listData.forEach((item) => {
				item.children && item.children.forEach((inItem) => {
					if(waitHashObjFlag) {
						this.nextHashObj = JSON.parse(JSON.stringify(inItem));
						waitHashObjFlag = false;
					}
					if(inItem.menuUrl == this.nowHashStr) {
						this.pervHashObj = JSON.parse(JSON.stringify(waitHashObj || {}));
						waitHashObjFlag = true;
					}

					waitHashObj = JSON.parse(JSON.stringify(inItem));
				});
			});
			waitHashObj = null;
		},
		// 获取当前的 hash 值
		setNowHash () {
			this.nowHashStr = location.hash.slice(1);
		},
	},
	mounted () {
		this.setNowHash();
		this.getPrevNextHashObj();
	},
	watch:{
		$route() {   
			this.setNowHash();
			this.getPrevNextHashObj();
		}
	}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.ygbh-footer{ width: 100%; overflow: hidden; padding: 40px 0; margin: 0 auto; line-height: 20px;}
.ygbh-footer .footer-l{ float: left; }
.ygbh-footer .footer-r{ float: right; }
.ygbh-footer .footer-link{ color: #333; text-decoration: none;}
.ygbh-footer .footer-link:hover{ color: #409eff; }
</style>